home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!austern
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.std.c++
- Subject: Re: istrstreams and width
- Date: 25 Mar 1996 10:22:46 PST
- Organization: Datalytics, Inc
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <3156E26D.74@datalytics.com>
- References: <4ibvn8$4gr@venus.roc.csci.csc.com>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: Mon, 25 Mar 1996 13:14:05 -0500
- X-Mailer: Mozilla 2.0 (WinNT; I)
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMVbknUy4NqrwXLNJAQEojQIAyn2r+TTkh8t7+hLV3RnNdcZ2j+anlSU/
- Gu+/yGvUrw9ki75FMgGZtBQG9ks02lCIvta6MM9UQz1rVqgkfaceDQ==
- =z+Rj
- Originator: austern@isolde.mti.sgi.com
-
- Tim Ottinger wrote:
- >
- > We've already worked around this (identified two way to do so) but we
- > wonder why it doesn't work this way:
- >
- > Given:
- > istrstream source;
- > int i;
- > string s;
- > source >> setw(2) >> i >> s;
- >
- > With fixed length fields (yes, we have to read mainframe data from time to
- > time, and a few other odd sources), sometimes the fields are butted up against
- > each other, and sometimes the strings have initial digit characters i them.
- >
- > When the stream contains "01115 N Neil", it would be nice if "01" and "115 N
- > Neil" were broken out, but every compiler we try pulls "01115" as the number,
- > and "N Neil" is the string.
- >
- > Of course, if we insert whitespace or use read, this works. And we should use
- > read() because we're doing fixed length, but I was wondering why setw()
- > doesn't apply to integer extractors.
- >
- > Surely a lot of people have to read fixed-length records, and this is a common
- > thing.
- >
- > Any thoughts?
-
- The setw manipulator, like the width mf, only specify a minimum
- field width. Thus, neither was intended to indicate the maximum
- number of characters to read. You only solutions are to use
- read or to parse the longer string yourself.
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-